__author__ = 'Aman'
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from yaasapp.models import AuctionData
from datetime import datetime
import random

def newAuction(request, num):
    AuctionData.objects.all().delete()
    userexist = User.objects.all()
    for us in userexist:
        if not us.is_superuser:
            us.delete()

    category = ['Foods', 'Home', 'Living Room', 'Cars', 'Electronics', 'Shoes', 'Shirts', 'Collectibles', 'Books and Magazines', 'Home electronics', 'Home', "Children's Accessories", 'Bags', 'Trips', 'Music', 'Game', 'Phones', 'Tickets', 'Construction', 'Miscellaneous', 'Art and design', 'Information Technology', 'Clothing']
    userlist = ['aman', 'Gaynelle', 'Danielle', 'Danelle', 'Tanika', 'Molly', 'Bernetta', 'Stacy', 'Augustine', 'Rey', 'Charolette', 'Rita', 'Alfredia', 'Kerry', 'Gretta', 'Alyse', 'Verlene', 'Kandy', 'Alba', 'Sharie', 'Jolynn', 'Patrice', 'Sueann', 'Sheryll', 'Francesco', 'Gerard', 'Kanesha', 'Danny', 'Caroyln', 'Fredric', 'Randa', 'Rachael', 'Avelina', 'Samatha', 'Heidi', 'Hannah', 'Leisa', 'Yevette', 'Noah', 'Jenice', 'Caitlin', 'Susannah', 'Joette', 'Terica', 'Mechelle', 'Deja', 'Erasmo', 'Deane', 'Loyce', 'Zula']

    if int(num)>50:
        num = '50'

    for i in range(0, int(num)):
            user = User(
                        username=userlist[i].lower(),
                        email=userlist[i]+'@'+userlist[i]+'.fi'
            )
            user.set_password(userlist[i].lower())
            user.save()

    user = User.objects.all()
    usernamelist = []
    for users in user:
        usernamelist.append(users.username)

    for j in range(0, int(num)):
            random.shuffle(category)
            random.shuffle(usernamelist)
            auction = AuctionData(
                                      title='Auction '+str(j+1),
                                      category=category[0],
                                      cPrice=str(random.randrange(1,1000)),
                                      iDesc='This item was created by '+usernamelist[0]+' and the item belongs to category '+category[0],
                                      sDate = datetime.now().strftime('%Y-%m-%d %H:%M'),
                                      user=usernamelist[0],status='active',
                                      eDate=datetime(random.choice(range(2015, 2016)),
                                                     random.choice(range(1, 12)),
                                                     random.choice(range(1, 28)),
                                                     random.choice(range(00, 23)),
                                                     random.choice(range(00, 59))),
                                      aOwner=usernamelist[0]
                                )
            auction.save()
    return HttpResponseRedirect('/home/')